package com.example.task1.util;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.example.task1.bean.AllServiceBean;
import com.example.task1.ui.AllService.DataAnalysis.DataAnalysisActivity;
import com.example.task1.ui.AllService.EventManagement.EventManagementActivity;
import com.example.task1.ui.AllService.Gover.GovernmentActivity;
import com.example.task1.ui.AllService.PublicBenefit.PublicBenefitActivity;
import com.example.task1.ui.AllService.YouthStation.YouthStationActivity;
import com.example.task1.ui.AllService.bus.BusActivity;
import com.example.task1.ui.AllService.garbage.GarbageActivity;
import com.example.task1.ui.AllService.hospital.HospitalActivity;
import com.example.task1.ui.AllService.law.LawActivity;
import com.example.task1.ui.AllService.library.LibraryActivity;
import com.example.task1.ui.AllService.life.LifeActivity;
import com.example.task1.ui.AllService.logistics.LogisticsActivity;
import com.example.task1.ui.AllService.movies.MoviesActivity;
import com.example.task1.ui.AllService.parking.ParkingActivity;
import com.example.task1.ui.AllService.pet.PetActivity;
import com.example.task1.ui.AllService.pet.PetCreateActivity;
import com.example.task1.ui.AllService.subway.SubwayActivity;
import com.example.task1.ui.AllService.takeout.TakeoutActivity;
import com.example.task1.ui.AllService.thehouse.TheHouseActivity;
import com.example.task1.ui.AllService.traffic.TrafficActivity;
import com.example.task1.ui.AllService.volunteer.VolunteerActivity;
import com.example.task1.ui.AllService.word.FindWordActivity;

import java.io.File;
import java.util.HashMap;
import java.util.List;

public class Utils {

    public static HashMap<Integer, Class> getServiceClass(List<AllServiceBean.RowsBean> rows) {
        HashMap<Integer, Class> map = new HashMap<>();
        for (AllServiceBean.RowsBean row : rows) {
            if ("数据分析".equals(row.getServiceName())) {
                map.put(row.getId(), DataAnalysisActivity.class);
            }
            if ("青年驿站".equals(row.getServiceName())) {
                map.put(row.getId(), YouthStationActivity.class);
            }
            if ("爱心捐赠".equals(row.getServiceName())) {
                map.put(row.getId(), PublicBenefitActivity.class);
            }
            if ("物流查询".equals(row.getServiceName())) {
                map.put(row.getId(), LogisticsActivity.class);
            }
            if ("宠物医院".equals(row.getServiceName())) {
                map.put(row.getId(), PetActivity.class);
            }
            if ("活动管理".equals(row.getServiceName())) {
                map.put(row.getId(), EventManagementActivity.class);
            }
            if ("找工作".equals(row.getServiceName())) {
                map.put(row.getId(), FindWordActivity.class);
            }
            if ("看电影".equals(row.getServiceName())) {
                map.put(row.getId(), MoviesActivity.class);
            }
            if ("找房子".equals(row.getServiceName())) {
                map.put(row.getId(), TheHouseActivity.class);
            }
            if ("外卖订餐".equals(row.getServiceName())) {
                map.put(row.getId(), TakeoutActivity.class);
            }
            if ("生活缴费".equals(row.getServiceName())) {
                map.put(row.getId(), LifeActivity.class);
            }
            if ("智慧交管".equals(row.getServiceName())) {
                map.put(row.getId(), TrafficActivity.class);
            }
            if ("门诊预约".equals(row.getServiceName())) {
                map.put(row.getId(), HospitalActivity.class);
            }
            if ("智慧巴士".equals(row.getServiceName())) {
                map.put(row.getId(), BusActivity.class);
            }
            if ("城市地铁".equals(row.getServiceName())) {
                map.put(row.getId(), SubwayActivity.class);
            }
            if ("停哪儿".equals(row.getServiceName())) {
                map.put(row.getId(), ParkingActivity.class);
            }
            if ("志愿服务".equals(row.getServiceName())) {
                map.put(row.getId(), VolunteerActivity.class);
            }
            if ("垃圾分类".equals(row.getServiceName())) {
                map.put(row.getId(), GarbageActivity.class);
            }
            if ("数字图书馆".equals(row.getServiceName())) {
                map.put(row.getId(), LibraryActivity.class);
            }
            if ("政府服务热线".equals(row.getServiceName())) {
                map.put(row.getId(), GovernmentActivity.class);
            }
            if ("教育".equals(row.getServiceName())) {
                map.put(row.getId(), LawActivity.class);
            }
        }
        return map;
    }

    public static File getFile(Context context, Uri uri) {
        String[] pro = {MediaStore.Images.Media.DATA};
        Cursor query = context.getContentResolver().query(uri, pro, null, null, null);
        if (query != null) {
            int indexOrThrow = query.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            query.moveToFirst();
            String string = query.getString(indexOrThrow);
            query.close();
            return new File(string);
        }
        return null;
    }

    public static void opImage(Activity context) {
        if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            // 如果权限未授予，请求权限
            ActivityCompat.requestPermissions(context, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 2);
        } else {
            // 权限已经授予，可以执行打开相册的操作
            Intent intent = new Intent(Intent.ACTION_PICK);
            intent.setType("image/*");
            context.startActivityForResult(intent, 1);
        }
    }

}
